home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 62 / Quick PC 62.iso / Programs / Ipswitch.IMail.Server.Pro.8.0.Winall / IMail8ec.exe / data1.cab / Web_Standard / rule_js.cgi < prev    next >
Encoding:
Text File  |  2003-05-07  |  11.9 KB  |  511 lines

  1.   function doButton_editrule(form,sButton)
  2.   {
  3.       var exit = 2;
  4.  
  5.       switch(sButton)
  6.       {
  7.         case "Update":
  8.           form.operadd.value = sButton;
  9.           exit = 3;
  10.           break;
  11.         case "Finish":
  12.           form.operadd.value = sButton;
  13.           exit = 1;
  14.           break;
  15.         case "Add":
  16.           form.operadd.value = sButton;
  17.           exit = 0;
  18.           break;
  19.         case "Change":
  20.           form.operadd.value = sButton;
  21.           exit = 0;
  22.           break;
  23.         case "And":
  24.           form.operadd.value = sButton;
  25.           break;
  26.         case "Or":
  27.           form.operadd.value = sButton;
  28.           break;
  29.         case "Remove":
  30.           form.operadd.value = sButton;
  31.           break;
  32.         case "Up":
  33.           form.operadd.value = sButton;
  34.           break;
  35.         case "Down":
  36.           form.operadd.value = sButton;
  37.           break;
  38.         default:
  39.           break;
  40.       }
  41.       
  42.       form.finalRule.value = makeFinalRule(form, exit);
  43.       if(form.finalRule.value == 0)
  44.       {
  45.         return;
  46.       }
  47.       
  48.       if (validateMe(form, exit))
  49.       {
  50.         clearListBox(form);
  51.         clearSearchArea_editrule(document.AddRule);
  52.       }
  53.   }
  54.     
  55.   function clearSearchArea_editrule(form)
  56.   {
  57.     if (form.searchfile.checked == true)
  58.     {
  59.       form.rulecontents.value = " ";
  60.     }
  61.     else
  62.       {
  63.         var searchString = form.rulecontents.value;
  64.   
  65.         if (searchString.length > 255)
  66.       {
  67.         alert("The text phrase is greater than 255 characters.")
  68.         return;
  69.       }
  70.       }
  71.       form.submit();
  72.   }
  73.  
  74.   function clearSearchContents_editrule(form)
  75.   {
  76.     form.rulecontents.value = " ";
  77.   }
  78.  
  79.     function displayRule(form)
  80.     {
  81.       //var msg = "This is the function that will parse the value of the selected option.";
  82.       //alert(msg);
  83.       var i = form.rulelist.selectedIndex;
  84.       var text = "";
  85.       var tempStr;
  86.       var gray = 1;
  87.       
  88.  
  89.       // Determine if an option is selected from
  90.       // the "rulelist" list box
  91.       
  92.       if (i != -1)
  93.       {
  94.         tempStr = form.rulelist.options[i].value;
  95.         
  96.         
  97.         // Select the option from the "field" list box whose
  98.         // value is equal to the first character of the selected
  99.         // option from the "rulelist" list box
  100.  
  101.         for (var x=0; x < form.field.length; x++)
  102.         {
  103.           if (tempStr.charAt(0) == form.field.options[x].value)
  104.           {
  105.             form.field.options[x].selected = 1;
  106.             gray = 0;
  107.             break;
  108.           }
  109.           else
  110.           {
  111.             gray = 1;
  112.           }
  113.         }
  114.         
  115.         // Determine the condition of the rule
  116.         
  117.         if (tempStr.charAt(1) == "~")
  118.         {
  119.           form.condition[0].checked = 1;
  120.           form.rulecase.checked = 0;
  121.           text = tempStr.substring(2,tempStr.length+1);
  122.         }
  123.         if (tempStr.charAt(1) == "=")
  124.         {
  125.           form.condition[0].checked = 1;
  126.           form.rulecase.checked = 1;
  127.           text = tempStr.substring(2,tempStr.length+1);
  128.         }
  129.         if (tempStr.charAt(1) == "!")
  130.         {
  131.           if (tempStr.charAt(2) == "~")
  132.           {
  133.             form.condition[1].checked = 1;
  134.             form.rulecase.checked = 0;
  135.             text = tempStr.substring(3,tempStr.length+1);
  136.           }
  137.           if (tempStr.charAt(2) == "=")
  138.           {
  139.             form.condition[1].checked = 1;
  140.             form.rulecase.checked = 1;
  141.             text = tempStr.substring(3,tempStr.length+1);
  142.           }
  143.         }
  144.         
  145.         // Determine if search phrase is in a file
  146.         
  147.         if (text.charAt(0) == ":")
  148.         {
  149.           // Display rule content in file
  150.  
  151.           var fileName = text.substring(2,text.length+1);
  152.           form.searchfile.checked = 1;
  153.           form.rulecontents.value = "";
  154.  
  155.           for (var x=0; x < form.rulefile.length; x++)
  156.           {
  157.             if (form.rulefile.value == fileName)
  158.             {
  159.               form.rulefile.options[x].selected = 1;
  160.             }
  161.           }
  162.         }
  163.         else
  164.         {
  165.  
  166.           // Display the rule content in text box
  167.  
  168.           form.searchfile.checked = 0;
  169.           form.rulecontents.value = text;
  170.           form.rulefile.selectedIndex = -1;
  171.         }
  172.  
  173.       }
  174.       else
  175.       {
  176.         gray = 1;
  177.       }
  178.  
  179.       if (gray == 1)
  180.       {
  181.         grayForm(form);
  182.       }
  183.       else
  184.       {
  185.         colorForm(form,'#FFFFFF');
  186.       }
  187.     }
  188.  
  189.     function grayForm(form)
  190.     {
  191.       form.field.selectedIndex = -1;
  192.       form.condition[0].checked = 0;
  193.       form.condition[1].checked = 0;
  194.       form.rulecontents.value = "";
  195.       form.rulecase.checked = 0;
  196.       form.searchfile.checked = 0;
  197.       form.rulefile.selectedIndex = -1;
  198.  
  199.       colorForm(form,'#E2E2E2');
  200.     }
  201.  
  202.     function colorForm(form, color)
  203.     {
  204.       
  205.       form.field.style.background = color;
  206.       //form.condition[0].style.background = color;
  207.       //form.condition[1].style.background = color;
  208.       form.rulecontents.style.background = color;
  209.       //form.rulecase.style.background = color;
  210.       //form.searchfile.style.background = color;
  211.       form.rulefile.style.background = color;
  212.     }
  213.  
  214.     function makeFinalRule(form, onExit)
  215.     {
  216.       var tempRule = "";
  217.       var delimiter = "||";
  218.       var tempStr = "";
  219.       var subtypeArray = new Array("+", "+!COPY!", "+", "!BOUNCE!", "NUL")
  220.  
  221.       for (var x=0; x < form.rulelist.length; x++)
  222.       {
  223.         if(onExit == 1)
  224.         {
  225.           tempStr = form.rulelist.options[x].value;
  226.           if (x == 0)
  227.           {
  228.             if (tempStr.charAt(0) != "!")
  229.             {
  230.               tempRule += form.rulelist.options[x].value;
  231.             }
  232.             else
  233.             {
  234.               alert("The first segment in the rule cannot be an \"" + tempStr.substring(1,tempStr.length -1) + "\".");
  235.               form.rulelist.options[x].selected = 1;
  236.               return 0;
  237.             }
  238.           }
  239.           else
  240.           {
  241.             if ((x % 2)!=0 && tempStr.charAt(0) != "!")
  242.             {
  243.               // If x is an odd number and the first character does not equal "!" 
  244.               // this let us know that there is an extra rule segment in the rule
  245.  
  246.               alert("The rule segment is not positioned in the rule correctly.");
  247.               form.rulelist.options[x].selected = 1;
  248.               return 0;
  249.             }
  250.             else if ((x % 2)==0 && tempStr.charAt(0) == "!")
  251.             {
  252.               // If x is an even number and the first character does equal "!"
  253.               // this let us know that there is an extra AND or OR condition
  254.  
  255.               alert("The rule segment is not positioned in the rule correctly.");
  256.               form.rulelist.options[x].selected = 1;
  257.               return 0;
  258.             }
  259.             else if (tempStr.charAt(0) == "!" && x == (form.rulelist.length - 1))
  260.             {
  261.               alert("The last segment in the rule cannot be an \"" + tempStr.substring(1,tempStr.length -1) + "\".");
  262.               form.rulelist.options[x].selected = 1;
  263.               return 0;
  264.             }
  265.             else
  266.             {
  267.               tempRule += form.rulelist.options[x].value;
  268.             }
  269.           }
  270.         }
  271.         else
  272.         {
  273.           if (x == 0)
  274.           {
  275.             tempRule += form.rulelist.options[x].value;
  276.           }
  277.           else
  278.           {
  279.             tempRule += delimiter + form.rulelist.options[x].value;
  280.           }
  281.         }
  282.       }
  283.       if(tempRule == "" && onExit == 1)
  284.       {
  285.         alert("Invalid rule: The rule will not be added to the file.");
  286.         return 0;
  287.       }
  288.       else
  289.       {
  290.         if (form.subtype.selectedIndex > -1 || form.subtype.selectedIndex < subtypeArray.length)
  291.         {
  292.           var i = form.subtype.selectedIndex;
  293.           var obformat = subtypeArray[form.subtype.options[i].value];
  294.           if (obformat.charAt(0) == "+")
  295.           {
  296.             var tempSrcStr = new String(form.destination.value);
  297.               if((tempSrcStr.search("@") != -1) && form.subtype.selectedIndex == 0)
  298.               {
  299.                 alert("Invalid mailbox name: \n\nThe '@' symbol is not allowed. ");
  300.                 form.destination.focus();
  301.                 return 0;
  302.               }
  303.         if((tempSrcStr.search("@") == -1) && form.subtype.selectedIndex == 2)
  304.               {
  305.                 alert("Invalid email address: \n\nPlease enter the full email address. ");
  306.                 form.destination.focus();
  307.                 return 0;
  308.               }
  309.         if((tempSrcStr.search(/\\|\//) != -1) && form.subtype.selectedIndex == 2)
  310.               {
  311.                 alert("Invalid email address: \n\nThere is an invalid symbol. ");
  312.                 form.destination.focus();
  313.                 return 0;
  314.               }
  315.  
  316.         if(form.subtype.selectedIndex != 2)
  317.         {
  318.                 // Replacing all '/' and '.' symbols with a '\'
  319.                 tempSrcStr = tempSrcStr.replace(/\/|\./g, "\\");
  320.         }
  321.         
  322.         tempRule += ":" + obformat.substring(1,obformat.length+1) + tempSrcStr;
  323.           }
  324.           else
  325.           {
  326.             tempRule += ":" + obformat;
  327.           }
  328.         }
  329.         else
  330.         {
  331.           tempRule += ":" + subtypeArray[0];
  332.         }
  333.       }
  334.       return tempRule;
  335.     }
  336.  
  337.     function validateSelect(form, sButton)
  338.     {
  339.       if(form.rulelist.selectedIndex != -1)
  340.       {
  341.         doButton_editrule(form,sButton);
  342.       }
  343.       else
  344.       {
  345.         alert("Please select an option from the list box to move \""+ sButton +".\"");
  346.       }
  347.     }
  348.  
  349.     function clearListBox(form)
  350.     {
  351.       for (var x=0; x < form.rulelist.length; x++)
  352.       {
  353.         form.rulelist.options[x].value = x;
  354.       }
  355.     }
  356.  
  357.     function setCondition(form)
  358.     {
  359.       if (form.rulecase.checked == 1)
  360.       {
  361.         form.condition[0].value = "="
  362.         form.condition[1].value = "!="
  363.       }
  364.       else
  365.       {
  366.         form.condition[0].value = "~"
  367.         form.condition[1].value = "!~"
  368.       }
  369.     }
  370.  
  371.     function validateMe(form, level)
  372.     {
  373.       if(level == 2)
  374.       {
  375.            if (form.rulelist.selectedIndex == -1)
  376.         {
  377.           alert("Please select a rule segment from the list box");
  378.           form.rulelist.focus();
  379.           return 0;
  380.         }
  381.         return 1; 
  382.       }
  383.       else if (level == 0)
  384.       {
  385.         // The user is just adding or updating a rule
  386.         
  387.         if(form.field.selectedIndex == -1)
  388.         {
  389.           alert("Please select a message area from the list box.");
  390.           form.field.focus();
  391.           return 0;
  392.         }
  393.         if(form.condition[0].checked==0 && form.condition[1].checked==0)
  394.         {
  395.           alert("Please select a condition.");
  396.           form.condition[0].focus();
  397.           return 0;
  398.         }
  399.         if(form.rulecontents.value == "" && form.searchfile.checked != 1)
  400.         {
  401.           alert("Please enter some content for the rule.");
  402.           form.rulecontents.focus();
  403.           return 0;
  404.         }
  405.         if(form.searchfile.checked == 1 && form.rulecontents.value != "")
  406.         {
  407.           alert("Content cannot be placed in the PHRASE field if the rule segment should read from a rule file.")
  408.           form.rulecontents.focus();
  409.           return 0;
  410.         }
  411.         if(form.searchfile.checked == 1 && form.rulefile.selectedIndex == -1)
  412.         {
  413.           alert("Please select a rule file from the list box.");
  414.           form.rulefile.focus();
  415.           return 0;
  416.         }
  417.         if(form.operadd.value == "Change" && form.rulelist.selectedIndex == -1)
  418.         {
  419.           alert("Please select a rule segment from the list box to update.");
  420.           form.rulelist.focus();
  421.           return 0;
  422.         }
  423.  
  424.         return 1;
  425.       }
  426.       else
  427.       {
  428.         return 1;
  429.       }
  430.  
  431.     }
  432.  
  433.     function sizeListbox(listBox)
  434.     {
  435.       // This function is designed to limit the length
  436.       // of the SELECT options for a given list box.
  437.       
  438.       for(var x=0; x < listBox.length; x++)
  439.       {
  440.         if(listBox.options[x].text.length > 65)
  441.         {
  442.           var tempStr = new String(listBox.options[x].text);
  443.           tempStr = tempStr.substr(0, 65) + "...";
  444.           listBox.options[x].text = tempStr;
  445.         }
  446.       }
  447.     }
  448.  
  449.     function selectMsgRadio(form, mode)
  450.     {
  451.       if (mode == 0)
  452.       {
  453.         var mbxOrAddr = new String(form.sendTo.value);
  454.  
  455.         <!--IMAIL.BeginIfDeleteRuleMsg-->
  456.         form.msgOpt[2].checked = 1;
  457.         <!--IMAIL.ElseBeginIfDeleteRuleMsg-->
  458.         if (mbxOrAddr.search("@") != -1)
  459.         {
  460.           form.sendToAddr.value = mbxOrAddr;
  461.           form.msgOpt[1].checked = 1;
  462.         }
  463.         else
  464.         {
  465.           form.sendToMbx.value = mbxOrAddr.replace(/\\/g,".");
  466.           form.sendToMbx.style.background='#FFFFFF';
  467.           form.sendToAddr.style.background='#E2E2E2';
  468.           form.msgOpt[0].checked = 1;
  469.         }
  470.         <!--IMAIL.EndBeginIfDeleteRuleMsg-->
  471.       }
  472.  
  473.       if(form.msgOpt[2].checked == 1)
  474.       {
  475.         form.sendToMbx.style.background='#E2E2E2';
  476.         form.sendToAddr.style.background='#E2E2E2';
  477.       }
  478.       else if (form.msgOpt[0].checked == 1)
  479.       {
  480.         form.sendToMbx.style.background='#FFFFFF';
  481.         form.sendToAddr.style.background='#E2E2E2';
  482.       }
  483.       else if (form.msgOpt[1].checked == 1)
  484.       {
  485.         form.sendToMbx.style.background='#E2E2E2';
  486.         form.sendToAddr.style.background='#FFFFFF';
  487.       }
  488.     }
  489.  
  490.   function disableTextbox(form)
  491.     {
  492.       if (form.subtype.options[3].selected==1 || form.subtype.options[4].selected==1)
  493.       {
  494.       // Disable the "destination" textbox
  495.         form.destination.style.background='#E2E2E2'
  496.       }
  497.       else
  498.       {
  499.       // Enable the "destination" textbox
  500.         form.destination.style.background='#FFFFFF'
  501.       }
  502.     }
  503.  
  504.     function startUp()
  505.     {
  506.       statusBarMsg(current);
  507.       grayForm(document.AddRule);
  508.       sizeListbox(document.AddRule.rulelist);
  509.       //selectMsgRadio(document.AddRule, 0);
  510.     disableTextbox(document.AddRule);
  511.     }